<!DOCTYPE html>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <script src="jquery-3.4.1.min.js"></script>
    <script src="echarts.js"></script>
    <title>Document</title>
</head>
<body>
    <div id="echarts" style="width: 100%;height: 480px;"></div>

    <script>
        function getData(errorArray, noErrorArray) {
            var errorData = new Array;
            var noErrorData = new Array;

            try {
                tmpstr = JSON.stringify(errorArray);
                substr = tmpstr.substring(2,tmpstr.length-2);
                errorData = substr.split(',');
            }catch(exception) {
                alert(exception);
            }

            try {
                tmpstr = JSON.stringify(noErrorArray);
                substr = tmpstr.substring(2,tmpstr.length-2);
                noErrorData = substr.split(',');
            }catch(exception) {
                alert(exception);
            }

            for(var i = 0; i < 5; i++) {
                console.log(errorData[i]+"----"+noErrorData[i]);
            }

            var dom = document.getElementById("echarts");
            var myChart = echarts.init(dom);
            option = {
                tooltip: {
                    trigger: 'axis',
                    axisPointer: {            // 坐标轴指示器，坐标轴触发有效
                        type: 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
                    }
                },
                legend: {
                    data: ['有违章', '无违章']
                },
                grid: {
                    left: '3%',
                    right: '4%',
                    bottom: '3%',
                    containLabel: true
                },
                xAxis: {
                    type: 'category',
                    data: ['90后', '80后', '70后', '60后', '50后']
                },
                yAxis: {
                    type: 'value'
                },
                series: [
                    {
                        name: '有违章',
                        type: 'bar',
                        stack: '总量',
                        label: {
                            show: true,
                        },
                        data: errorData
                    },
                    {
                        name: '无违章',
                        type: 'bar',
                        stack: '总量',
                        label: {
                            show: true,
                        },
                        data: noErrorData
                    }
                ]
            };
            myChart.setOption(option, true);
        }    
    
    </script>
</body>
</html>